package com.graduate.after.web.control;

import com.graduate.after.bean.*;
import com.graduate.after.constants.StatusCode;
import com.graduate.after.exception.GraduateException;
import com.graduate.after.service.DetailDataService;
import com.graduate.after.service.SlideShowService;
import com.graduate.after.utils.Result;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/detail")
public class DetailControl {

    @Autowired
    private SlideShowService slideShowService;

    @Autowired
    private DetailDataService detailDataService;

    @RequestMapping("/slideShowAndData")
    public Result detailSlideShow(Long iid) {
        if(iid == null) {
            throw new GraduateException(StatusCode.PARAM_IS_BLANK);
        }
        Map map = new HashMap();
        List<SlideShow> slideShows = slideShowService.detailSlideShowSelect(iid);
        DetailBaseData detailBaseData = detailDataService.detailBaseDataSelect(iid);
        List<DetailDescript> detailScenic = detailDataService.detailScenicSelect(iid);
        List<DetailDescript> detailHistory = detailDataService.detailHistorySelect(iid);
        List list = detailDataService.detailParamsSelect(iid);
        List<DetailComment> detailComments = detailDataService.detailCommentSelect(iid);

        map.put("topImages",slideShows);
        map.put("baseData",detailBaseData);
        map.put("scenic",detailScenic);
        map.put("history",detailHistory);
        map.put("params",list);
        map.put("comments",detailComments);

        return Result.success(map);
    }
}
